package fields;
import game.Player;

public class Territory extends Ownable {

	private int[] rent;
	private int houses, propertiesInGroup, housePrice;
	private String color;
	
	public Territory (int number, String name, int price, int[] rent, int propertiesInGroup, int housePrice, String color){
		
		super (number, name, price); 
		this.rent = rent;
		this.propertiesInGroup=propertiesInGroup;
		this.color=color;
		this.housePrice=housePrice;
	}
	
	public void landOnField(Player sp)
	{
		if (!isOwnable() && sp!=owner && !owner.isInJail() && !isPawned())
		{
			sp.transfer(getRent(), owner);
		}
		else if (isOwnable()){
			if (sp.getChoice()) {
				buy(sp);
				sp.setChoice(false);
			}
		}
		
	}
	
	public String getColor() {
		return color;
	}
	
	public int getRent() {
		return rent[houses];
	}
	
	public int getHousePrice() {
		return housePrice;
	}
	
	public int getHouses() {
		return houses;
	}
	
	public int getPropertiesInGroup() {
		return propertiesInGroup;
	}
	
	public void addBuilding() {
		if (owner.canBuildAtProperty(getNumber(), color) && houses < 5) {
			houses++;
			owner.withdraw(housePrice);
		}
	}
	
	public void removeBuilding() {
		if (houses>0) {
			houses--;
			owner.deposit(housePrice/2);
		}
	}
	
	public void setHouses(int houses) {
		this.houses=houses;
	}
		
}